package com.osce.web.controller.system;

import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.entity.entity.DeptTransferApply;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.system.service.IDeptTransferApplyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 申请更换部门审批Controller
 *
 * @author hdj
 * @since 2025-11-05
 */
@RestController
@RequestMapping("/system/apply")
public class DeptTransferApplyController extends BaseController {

    @Resource
    private IDeptTransferApplyService deptTransferApplyService;

/**
 * 查询申请更换部门审批列表
 */
@PreAuthorize("@ss.hasPermi('system:apply:list')")
@GetMapping("/list")
    public TableDataInfo list(DeptTransferApply deptTransferApply) {
        startPage();
        List<DeptTransferApply> list = deptTransferApplyService.selectDeptTransferApplyList(deptTransferApply);
        return getDataTable(list);
    }

    /**
     * 查询自己的申请记录更换部门审批列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/applyList")
    public  AjaxResult applyList(DeptTransferApply deptTransferApply) {
        Long userId = getLoginUser().getUserId();
        deptTransferApply.setUserId(userId);
        List<DeptTransferApply> list = deptTransferApplyService.selectDeptTransferApplyList(deptTransferApply);
        return AjaxResult.success(list);
    }

    /**
     * 导出申请更换部门审批列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "申请更换部门审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeptTransferApply deptTransferApply) {
        List<DeptTransferApply> list = deptTransferApplyService.selectDeptTransferApplyList(deptTransferApply);
        ExcelUtil<DeptTransferApply> util = new ExcelUtil<DeptTransferApply>(DeptTransferApply. class);
        util.exportExcel(response, list, "申请更换部门审批数据");
    }

    /**
     * 获取申请更换部门审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(deptTransferApplyService.selectDeptTransferApplyById(id));
    }

    /**
     * 新增申请更换部门审批
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "申请更换部门审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptTransferApply deptTransferApply) {
        return toAjax(deptTransferApplyService.insertDeptTransferApply(deptTransferApply));
    }

    /**
     * 修改申请更换部门审批
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "申请更换部门审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptTransferApply deptTransferApply) {
        return toAjax(deptTransferApplyService.updateDeptTransferApply(deptTransferApply));
    }

    /**
     * 删除申请更换部门审批
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "申请更换部门审批", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deptTransferApplyService.deleteDeptTransferApplyByIds(ids));
    }
}
